<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
       
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <h:form>
            <p:panel header="Sent Messages">
                <p:messages id="msgs" showDetail="true"/>
                <p:panel>
                    <p:commandButton value="Compose New" ajax="false" action="#{msgManagerBean.redirectToCreateNewMsg}"/>
                    <p:commandButton value="Delete Selected" onclick="dlg2.show()"/>
                </p:panel>
                <p:dataTable value="#{msgManagerBean.allMySentMessages}" var="msg" selection="#{msgManagerBean.selectedDeletion}"
                             style="width: 100%"
                             paginator="true" rows="15"  
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="15,20,25"
                             widgetVar="sentMsgs">
                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <h:inputText id="globalFilter" onkeyup="sentMsgs.filter()" />
                        </p:outputPanel>
                    </f:facet>

                    <p:column selectionMode="multiple" />

                    <p:column headerText="Subject"
                              filterBy="#{msg.subject}">
                        <p:commandLink value="#{msg.subject}" ajax="false" action="#{msgManagerBean.viewOneSentMsg(msg.id)}"/>
                    </p:column>

                    <p:column headerText="Sender"
                              filterBy="#{msgManagerBean.getSenderFullName(msg.senderAccId)}">
                        <h:outputText value="#{msgManagerBean.getSenderFullName(msg.senderAccId)}"/>
                    </p:column>

                    <p:column headerText="Time"
                              filterBy="#{msg.formattedDate}">
                        <h:outputText value="#{msg.formattedDate}"/>
                    </p:column>

                    <p:column headerText="Options">
                        <p:commandButton value="View" ajax="false" action="#{msgManagerBean.viewOneSentMsg(msg.id)}"/>
                        <p:commandButton value="Delete" onclick="dlg1.show()" action="#{msgManagerBean.selectMessage(msg.id)}"/>
                    </p:column>
                </p:dataTable>
            </p:panel>

            <p:confirmDialog widgetVar="dlg1" message="Are you sure to delete the selected message?"
                             showEffect="explode" hideEffect="explode"
                             header="Confirm to Delete" severity="alert">
                <p:commandButton value="Delete" onstart="dlg1.hide()" ajax="false" update="msgs"
                                 action="#{msgManagerBean.deleteOneMsg}"/>
                <p:commandButton value="Cancel" onclick="dlg1.hide()" type="button" />
            </p:confirmDialog>

            <p:confirmDialog widgetVar="dlg2" message="Are you sure to delete the selected messages?"
                             showEffect="explode" hideEffect="explode"
                             header="Confirm to Delete" severity="alert">
                <p:commandButton value="Delete" onstart="dlg2.hide()" ajax="false" update="msgs"
                                 action="#{msgManagerBean.deleteManyMsgs}"/>
                <p:commandButton value="Cancel" onclick="dlg2.hide()" type="button" />
            </p:confirmDialog>
        </h:form>
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
